package leetcode;

import common.Util;

/**
 * 矩阵旋转
 */
public class LeetCode_0107 {
    public void rotate(int[][] matrix) {
        int n = matrix.length;
        for (int i = 0; i < n / 2; i++) {
            for (int j = i; j < n - 1 - i; j++) {
                int x = i, y = j, replace = matrix[x][y];
                for (int k = 0; k < 4; k++) {
                    int nextX = y, nextY = n - x - 1;
                    int temp = matrix[nextX][nextY];
                    matrix[nextX][nextY] = replace;
                    replace = temp;
                    x = nextX;
                    y = nextY;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[][] i = new int[][]{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
        LeetCode_0107 leetCode_0107 = new LeetCode_0107();
        leetCode_0107.rotate(i);
        Util.print2Array(i);
    }
}